package com.gitee.helioz.openai.api.endpoint.embeddings;

import com.gitee.helioz.openai.api.OpenAiService;
import com.gitee.helioz.openai.api.dto.embeddings.EmbeddingRequest;
import com.gitee.helioz.openai.api.dto.embeddings.EmbeddingResponse;
import com.gitee.helioz.openai.common.constants.OpenAiApiUrl;
import com.gitee.helioz.openai.common.util.json.GsonUtil;
import lombok.RequiredArgsConstructor;

/**
 * 〈嵌入服务〉
 *
 * @author <a href="https://gitee.com/helioz">Morning Starr</a>
 */
@RequiredArgsConstructor
public class EmbeddingServiceImpl implements EmbeddingService {

    private final OpenAiService openAiService;

    @Override
    public EmbeddingResponse create(EmbeddingRequest embeddingRequest) {
        String requestJson = GsonUtil.toJson(embeddingRequest);
        String responseStr = openAiService.post(OpenAiApiUrl.Embeddings.CREATE_EMBEDDINGS.getUrl(openAiService.getApiHost()), requestJson);
        return GsonUtil.fromJson(responseStr, EmbeddingResponse.class);
    }
}
